package com.chixing.day05.review;

public class CheckPassword {
    public static boolean check(String password){
        //只要其中一个不满足要求，立即返回false

        return checkLength(password)&&checkCharacter(password)&&checkType(password);

    }
    //检查长度
    private static boolean checkLength(String password){
        return password.length()>=8;
    }
    //密码只能由大写字母，小写字母，数字构成
    private static boolean checkCharacter(String password){
        for(int i=0;i<=password.length();i++){
            char c=password.charAt(i);
            boolean isValid=false;
            if((!(c>='0'&&c<='9')||(c>'A'&&c<='Z')||(c>='a'&&c<='z'))){
                return false;
            }


        }
        return true;
    }
    // 密码不能以数字开头；密码中至少出现大写字母，小写字母和数字这三种字符类型中的两种
    private static boolean checkType(String password){
        char firstChar=password.charAt(0);
        if(firstChar>='0'&&firstChar<='9')
        return false;

        int numCount=0;
        int upperCharCount=0;
        int lowerCharCount=0;

        for (int i=0;i<password.length();i++){
            char c=password.charAt(i);
            if(c>='0'&&c<='9')
                numCount++;
            if(c>='A'&&c<='Z')
                upperCharCount++;
            if(c>='a'&&c<='z')
                lowerCharCount++;

        }
        return true;
    }

}
